package com.hysf.ioc.pro6_ioc_conditional;

import com.hysf.ioc.pro5_ioc_import.other.Apple;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan(basePackages = "com.hysf.pro6_ioc_conditional")
public class Pro6_Test {
	@Bean
	public SystemConditional systemConditional() {
		return new SystemConditional();
	}
	
	@Bean
	public Apple apple() {
		systemConditional();
		return new Apple();
	}
	
	public static void main(String[] args) {
		ApplicationContext context = new AnnotationConfigApplicationContext(Pro6_Test.class);
		String[] beanDefinitionNames = context.getBeanDefinitionNames();
		for (String beanDefinitionName : beanDefinitionNames) {
			System.out.println(beanDefinitionName);
		}
		
//		ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) context.getAutowireCapableBeanFactory();
//		DefaultSingletonBeanRegistry registry = (DefaultSingletonBeanRegistry) beanFactory;
//		// 获取所有单例 Bean 的名称
//		String[] singletonNames = registry.getSingletonNames();
//
//		System.out.println("单例 Bean 数量: " + singletonNames.length);
//		for (String name : singletonNames) {
//			System.out.println("Bean 名称: " + name + ", 类型: " + registry.getSingleton(name).getClass().getName());
//		}
	}
}
